@*
    职级管理页面
*@
@{
    ViewData["Title"] = "职级管理";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>职级管理</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <style>
        .layui-form-item .layui-input-inline {
            width: 180px;
        }

        .layui-form-item .salary-range .layui-input-inline {
            width: 80px;
        }

        .layui-table-tool-temp {
            padding-right: 120px;
        }

        .layui-btn-container {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    @Html.AntiForgeryToken()
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">职级管理</div>
            <div class="layui-card-body">
                <!-- 搜索栏 -->
                <form class="layui-form" lay-filter="searchForm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键词</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="职级编码/层次/名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">职级编码</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobGradeCoding" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">职级层次</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobGradeLevel" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">最低薪资</label>
                            <div class="layui-input-inline">
                                <input type="number" name="minSalaryRangelower" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">最高薪资</label>
                            <div class="layui-input-inline">
                                <input type="number" name="minSalaryRangelimits" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn" lay-submit lay-filter="searchBtn">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>

                <!-- 表格工具栏 -->
                <div class="layui-btn-container">
                    <button type="button" class="layui-btn layui-btn-sm" id="addBtn"><i class="layui-icon">&#xe654;</i> 新增</button>
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="batchDeleteBtn"><i class="layui-icon">&#xe640;</i> 批量删除</button>
                    <button type="button" class="layui-btn layui-btn-sm" id="exportBtn"><i class="layui-icon">&#xe67d;</i> 导出</button>
                </div>

                <!-- 数据表格 -->
                <table id="positionLevelTable" lay-filter="positionLevelTable"></table>

                <!-- 操作列模板 -->
                <script type="text/html" id="operationTpl">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
                </script>
            </div>
        </div>
    </div>



    <script src="~/layui/layui.js"></script>
    <script>
        layui.use(['table', 'form', 'layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.jquery;

            // 初始化表格
            var tableIns = table.render({
                elem: '#positionLevelTable',
                url: '/PositionLevel/GetPositionLevels',
                page: true,
                limits: [10, 20, 50, 100],
                limit: 10,
                cols: [[
                    { type: 'checkbox' },
                    { field: 'id', title: 'ID', width: 60, sort: true },
                    { field: 'jobGradeCoding', title: '职级编码', width: 120 },
                    { field: 'jobGradeLevel', title: '职级层次', width: 100 },
                    { field: 'jobGradeLevelName', title: '职级层次名称', width: 150 },
                    { field: 'salaryRangelower', title: '薪资范围下限', width: 120, sort: true },
                    { field: 'salaryRangelimits', title: '薪资范围上限', width: 120, sort: true },
                    { field: 'referenceColumn', title: '备注' },
                    { title: '操作', width: 120, toolbar: '#operationTpl', fixed: 'right' }
                ]],
                response: {
                    statusCode: 0
                },
                parseData: function (res) {
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.count,
                        "data": res.data
                    };
                }
            });

            // 监听搜索按钮
            form.on('submit(searchBtn)', function (data) {
                tableIns.reload({
                    where: data.field,
                    page: { curr: 1 }
                });
                return false;
            });

            // 监听表格工具条
            table.on('tool(positionLevelTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    // 编辑
                    layer.open({
                        type: 2,
                        title: '编辑职级',
                        area: ['700px', '600px'],
                        content: '/PositionLevel/AddEdit?id=' + data.id
                    });
                } else if (obj.event === 'delete') {
                    // 删除
                    layer.confirm('确定删除该职级吗？', function (index) {

                        $.ajax({
                            url: '/PositionLevel/DeletePositionLevel',
                            type: 'POST',
                            data:{id:data.id},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg('删除成功');
                                    tableIns.reload();
                                } else {
                                    layer.msg('删除失败: ' + res.message);
                                }
                            },
                            error: function (xhr) {
                                console.error('删除请求错误:', xhr);
                                layer.msg('服务器错误: ' + (xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText));
                            }
                        });
                        layer.close(index);
                    });
                }
            });

            // 新增按钮点击事件
            $('#addBtn').on('click', function () {
                layer.open({
                    type: 2,
                    title: '新增职级',
                    area: ['700px', '600px'],
                    content: '/PositionLevel/AddEdit'
                });
            });

            // 批量删除按钮点击事件
            $('#batchDeleteBtn').on('click', function () {
                var checkStatus = table.checkStatus('positionLevelTable');
                var data = checkStatus.data;
                if (data.length === 0) {
                    layer.msg('请选择要删除的数据');
                    return;
                }
                var ids = data.map(function (item) {
                    return item.id;
                });

                layer.confirm('确定删除所选的' + data.length + '条数据吗？', function (index) {
                    $.ajax({
                        url: '/PositionLevel/BatchDeletePositionLevels',
                        type: 'POST',
                        data: {
                            ids: ids,
                        },
                        success: function (res) {
                            if (res.success) {
                                layer.msg('批量删除成功');
                                tableIns.reload();
                            } else {
                                layer.msg('批量删除失败: ' + res.message);
                            }
                        },
                        error: function (xhr) {
                            console.error('批量删除请求错误:', xhr);
                            layer.msg('服务器错误: ' + (xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText));
                        }
                    });
                    layer.close(index);
                });
            });

            // 导出按钮点击事件
            $('#exportBtn').on('click', function () {
                var searchParams = form.val('searchForm');
                searchParams.__RequestVerificationToken = $('input[name="__RequestVerificationToken"]').val();
                var url = '/PositionLevel/ExportPositionLevels?' + $.param(searchParams);
                window.location.href = url;
            });
        });
    </script>
</body>
</html> 